<?php

class Doctrine_Model_CajaDiariaDao extends Doctrine_Model_BaseDao {

    public function obtenerTodos() {
        return $this->getEntityManager()
                        ->createQuery('select c from Doctrine_Model_Entities_CajaDiaria c')
                        ->getResult();
    }

    
    public function obtenerPorId($id) {
        return $this->getEntityManager()->find('Doctrine_Model_Entities_CajaDiaria', $id);
    }

    public function guardar(Doctrine_Model_Entities_CajaDiaria $unaCaja) {
        try {

            $this->getEntityManager()->persist($unaCaja);
            $this->getEntityManager()->flush();
            return true;
        } catch (Exception $e) {
            echo ($e->xdebug_message);
            $logger = Zend_Registry::get('logger');
            $logger->log("Error:" . $e->getMessage(), Zend_Log::ERR);
            return false;
        }
    }

    public function eliminar(Doctrine_Model_Entities_CajaDiaria $unaCaja) {
        try {
            $this->getEntityManager()->remove($unaCaja);
            $this->getEntityManager()->flush();

            return true;
        } catch (Exception $e) {
            $logger = Zend_Registry::get('logger');

            $logger->log("Error: " . $e->getMessage(), Zend_Log::ERR);
            return false;
        }
    }

    public function obtenerPorFechaYSucursal($fecha,$sucursalId) {
 
        if (!empty($fecha) && !empty($sucursalId)) {
          
            $result = $this->getEntityManager()
                    ->createQuery("select c from Doctrine_Model_Entities_CajaDiaria c JOIN c.sucursal s  where  c.fecha='".$fecha."' AND s.id=".$sucursalId )
                    ->getResult();
            return $result[0];
        } else {
            return NULL;
        }
    }

       

}

